<?php
namespace App\Logic;


use App\Http\Logic\BaseLogic;
use App\Models\SwtMachineGoodsLog;
use App\Models\SwtRequestLog;
use App\Models\SwtZyLog;


/**
 * 添加所有日志
 * @package App\Logic
 * @class LogLogic
 * @author 丿Evil 2025-01-08
 */
class LogLogic extends BaseLogic {

    public static function setMachineGoodsLogs($machine_id, $source_id, $goods, $desc)
    {
        $data = [];

        foreach($goods as $good) {
            $data[] = [
                'machine_id'     => $machine_id,
                'source_id'      => $source_id,
                'goods_name'     => $good["goods_name"],
                'num'            => $good["num"],
                "desc"           => $desc,
                'created_at'     => date("Y-m-d H:i:s",time()),
                'updated_at'     => date("Y-m-d H:i:s",time()),
            ];
        }

        SwtMachineGoodsLog::insert($data);
    }

    public static function setZyLogs($order_sn, $member_id, $amount, $desc)
    {
        $data = [
            'order_id'  => $order_sn,
            'member_id' => $member_id,
            'amount'    => $amount,
            'desc'      => $desc
        ];

        SwtZyLog::create($data);
    }

    public static function setDheLogs($request_id, $path, $input)
    {
        if(is_array($input)){
            $input = json_encode($input, 256);
        }

        SwtRequestLog::create([
            'log_type'   => 1,
            'request_id' => $request_id,
            'path'       => $path,
            'input'      => $input
        ]);
    }


    public static function setBjLogs($request_id, $path, $input)
    {
        if(is_array($input)){
            $input = json_encode($input, 256);
        }

        SwtRequestLog::create([
            'log_type'   => 2,
            'request_id' => $request_id,
            'path'       => $path,
            'input'      => $input
        ]);
    }

    public static function setTyLogs($request_id, $path, $input)
    {
        if(is_array($input)){
            $input = json_encode($input, 256);
        }

        SwtRequestLog::create([
            'log_type'   => 3,
            'request_id' => $request_id,
            'path'       => $path,
            'input'      => $input
        ]);
    }


}
